#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-09-19 14:25:34
# @Author  : Your Name (you@example.org)
# @Link    : link
# @Version : 1.0.0
import datetime
import decimal


class BaseData(object):

    def __init__(self, *args, **kwargs):
        self.id = None
        self.name = None,
        self.type = None,
        self.cdate = None,
        self.cen_lon = None,
        self.cen_lat = None,
        self.l_on_lon = None,
        self.l_on_lat = None,
        self.r_d_lon = None,
        self.r_d_lat = None,
        self.author = None,
        self.cpath = None,
        self.recordp = None,
        self.rtime = None,
        self.format = None,
        self.details = None,
        self.sname = None

    def get_value(self, data):
        # data = data[:-1]  # basedata 暂时未加入
        values = [self.id, self.name, self.type, self.cdate, self.cen_lon, self.cen_lat, self.l_on_lon, self.l_on_lat,
                  self.r_d_lon, self.r_d_lat, self.author, self.cpath, self.recordp, self.rtime, self.format,
                  self.details, self.sname]

        for i in range(len(data)):
            if data[i] is None:
                values[i] = ''
            elif type(data[i]) is str:
                # values[i] = bytes(data[i]).decode("utf-8")
                values[i] = data[i]
            elif type(data[i]) is datetime.datetime:
                values[i] = data[i].strftime('%Y-%m-%d')
            elif type(data[i]) is decimal.Decimal:
                values[i] = str(data[i])
            else:
                values[i] = data[i]

        keys = ["id", "name", "type", "cdate", "cen_lon", "cen_lat", "l_on_lon", "l_on_lat",
                "r_d_lon", "r_d_lat", "author", "cpath", "recordp", "rtime", "format", "details", "sname"]

        return dict(zip(keys, values))
